/*
 *  JDiv - API for Multimedia Application
 *  http://jdiv.sourceforge.net 
 *  ------------------------------------
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software 
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 *
 */

package com.jdiv.internalClasses;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Application.ApplicationType;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.jdiv.JDiv;
import com.jdiv.kernel.JDivResources;
import com.jdiv.kernel.JDivSystem;

public class JDivFont extends JDivDisposable {
	
	Label.LabelStyle fontStyle;
	
	FileHandle fileFnt, filePng;
	BitmapFont font;
	
	//-----------------------------------------------------------------------------
	// JDivFont: Inicializa la fuente
	//-----------------------------------------------------------------------------	
		
	 public JDivFont( FileHandle fileFnt, FileHandle filePng ){
		 this.fileFnt = fileFnt;
		 this.filePng = filePng;
		 font = null;
		 fontStyle = null;
	 }
	 
	//-----------------------------------------------------------------------------
	// JDivFont: Inicializa la fuente por defecto
	//-----------------------------------------------------------------------------		
	 
	public JDivFont( ){
		
		if(JDivResources.listFonts.listFonts.size() == 0){
		 fileFnt    = null;
		 filePng = null;
		 
		 if( Gdx.app.getType() != ApplicationType.WebGL )
			 font = new BitmapFont();
		 else{
			 FileHandle file = Gdx.files.internal("data/fonthtml/default.fnt");
			 
			 if( !file.exists() ) return;
			 
		     font = new BitmapFont(file, false);
		 }
		 
		 fontStyle = new Label.LabelStyle(font, null);
		 
		 font.getRegion().getTexture().setFilter(JDivSystem.jdivTextureFilter, JDivSystem.jdivTextureFilter);
		 
		 JDivResources.listFonts.listFonts.add(this);
		}
		
	}

	
	//-----------------------------------------------------------------------------
	// getFontStyle: Obtenemos el estilo de la fuente
	//-----------------------------------------------------------------------------
	
	public Label.LabelStyle getFontStyle(){
		return fontStyle;
	}
		
	
	//-----------------------------------------------------------------------------
	// newFont: Obtenemos el bitmap de la fuente
	//-----------------------------------------------------------------------------		
	
	public BitmapFont getFont(){
		return font;
	}
	 
	//-----------------------------------------------------------------------------
	// newFont: Creamos la fuente
	//-----------------------------------------------------------------------------	
		
	 public void load()
	 {
		 font = new BitmapFont(fileFnt, false);
		 
		 if( font != null ){
			 font.getRegion().getTexture().setFilter(JDivSystem.jdivTextureFilter, JDivSystem.jdivTextureFilter);
			 
			 fontStyle   = new Label.LabelStyle(font, null);
		 }else
			 JDiv.system.log("ERROR, newFont() - Can not load skin: " + fileFnt.path() );
	 }
	 
	 //-----------------------------------------------------------------------------
	 // dispose: Liberamos la fuente
	 //-----------------------------------------------------------------------------	
		
	 public void dispose()
	 {
		 if( font != null )
			 font.dispose();
		 
		 font = null;
		 fontStyle = null;
	 }
}
